package edu.gznu.ics.fast.pulsar.controller.prestoacc.picController;


import edu.gznu.ics.fast.pulsar.model.vo.web.CompareQueryResultVO;
import edu.gznu.ics.fast.pulsar.model.vo.web.CompareQueryVO;
import edu.gznu.ics.fast.pulsar.model.vo.web.PageVO;
import edu.gznu.ics.fast.pulsar.model.vo.web.PicQueryResultVO;
import edu.gznu.ics.fast.pulsar.service.prestoacc.picService.CompareQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by fei-zyx on 2016/10/19.
 */
@Controller

public class CompareQueryController {

    @Autowired

    private CompareQueryService compareQueryService;

    @RequestMapping(method = RequestMethod.POST, value = "/compareQuery", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<CompareQueryResultVO> compareQuery(@RequestBody CompareQueryVO obj){

        //int page=Integer.parseInt(request.getParameter("page"));
        //int row=(int)rows;
        //System.out.println(page);
        //System.out.print(pageHelper.getPage()+"***"+pageHelper.getRows());
        List<CompareQueryVO> listTemp=new ArrayList<CompareQueryVO>();
        List<CompareQueryResultVO> list=new ArrayList<CompareQueryResultVO>();
        CompareQueryVO compareQueryVO;
        System.out.println(obj.getPage()+"--------"+obj.getRows());
        System.out.println(obj.getFileId()+"/////"+obj.getDec2000Rank());

        listTemp=compareQueryService.queryByPicAndFits(obj);
        CompareQueryVO obj2=listTemp.get(0);

        listTemp.get(0).setDmRank(obj.getDmRank());
        listTemp.get(0).setpRank(obj.getpRank());
        listTemp.get(0).sethRank(obj.gethRank());
        listTemp.get(0).setRa2000Rank(obj.getRa2000Rank());
        listTemp.get(0).setDec2000Rank(obj.getDec2000Rank());
        System.out.println("Rank:"+listTemp.get(0).getDec2000Rank());

        compareQueryVO=listTemp.get(0);
        list=compareQueryService.queryByRank(compareQueryVO,obj2);
        //System.out.println(list.get(0).getPuslarName()+"####");


        return list;

//        select file_id,dm,picname,TASK_ID,PICDM,PTOPO,PIC_4_HASLORENTZ,PIC_4_PEAKNUM from t_pic_info where 1=1 and TASK_ID=1 and PIC_4_HASLORENTZ BETWEEN 1 AND 1 and PIC_4_PEAKNUM BETWEEN 1 AND 1

    }

    @RequestMapping(method = RequestMethod.POST, value = "/matchUpdate", produces = "application/json;charset=UTF-8")

    public @ResponseBody String matchUpdate(@RequestBody PicQueryResultVO obj){
        System.out.println("success");

        compareQueryService.matchUpdate(obj);
        System.out.println("successful!");

        return "Successful";


//        select file_id,dm,picname,TASK_ID,PICDM,PTOPO,PIC_4_HASLORENTZ,PIC_4_PEAKNUM from t_pic_info where 1=1 and TASK_ID=1 and PIC_4_HASLORENTZ BETWEEN 1 AND 1 and PIC_4_PEAKNUM BETWEEN 1 AND 1

    }
    @RequestMapping(method = RequestMethod.POST, value = "/notesUpdate", produces = "application/json;charset=UTF-8")

    public @ResponseBody String notesUpdate(@RequestBody PicQueryResultVO obj){
        compareQueryService.notesUpdate(obj);
        //System.out.println("successful!");

        return "Successful";


//        select file_id,dm,picname,TASK_ID,PICDM,PTOPO,PIC_4_HASLORENTZ,PIC_4_PEAKNUM from t_pic_info where 1=1 and TASK_ID=1 and PIC_4_HASLORENTZ BETWEEN 1 AND 1 and PIC_4_PEAKNUM BETWEEN 1 AND 1

    }


}

